package com.atguigu.gulimall.seckill.controller;
import com.atguigu.common.utils.R;
import com.atguigu.gulimall.seckill.service.SeckillService;
import com.atguigu.gulimall.seckill.to.SecKillSkuRedisTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Controller
public class SeckillController {
    @Autowired
    private SeckillService seckillService;
    @ResponseBody
    @GetMapping("/currentSeckillSkus")
    public R  getCurrentSeckillSkus(){ //  获取当前场次的所有要参加秒杀的商品
        List<SecKillSkuRedisTo> list=seckillService.getCurrentSeckillSkus();
        return R.ok().setData(list);
    }
    @ResponseBody
    @GetMapping("/sku/seckill/{skuId}")
    public R  getSkuSeckillInfo(@PathVariable Long  skuId){
        SecKillSkuRedisTo to=seckillService.getSkuSeckillInfo(skuId);
        return  R.ok().setData(to);
    }
    @GetMapping("/kill")
    public String secKill(@RequestParam  String  killId,
                          @RequestParam  String key,
                          @RequestParam    Integer num
                          , Model model
                          ){
       String orderSn= seckillService.kill(killId,key,num);
       model.addAttribute("orderSn",orderSn);
       return "success";
    }


       @GetMapping("kill2")  //  秒杀接口:   参数  num  sku_id    用户id




        public void kill2(@RequestParam  String  killId,
                         @RequestParam  String key,
                         @RequestParam    Integer num){




           String orderSn= seckillService.kill2(killId,key,num);








        }





}
